package com.a.lib_utils;

import android.content.Context;
import androidx.annotation.LayoutRes;
import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

public class DialogUtil {

    public static QMUITipDialog getTip(Context c, @QMUITipDialog.Builder.IconType int type, boolean cancelable) {
        return new QMUITipDialog.Builder(c).setIconType(type).create(cancelable);
    }

    public static QMUITipDialog getTip(Context c, @QMUITipDialog.Builder.IconType int type, String tipWord, boolean cancelable) {
        return new QMUITipDialog.Builder(c).setIconType(type).setTipWord(tipWord).create(cancelable);
    }

    public static QMUITipDialog getCustomDialog(Context c, @LayoutRes int layId) {
        return new QMUITipDialog.CustomBuilder(c).setContent(layId).create();
    }

    public static QMUIDialog.EditTextDialogBuilder getEditTextDialog(Context c) {
        return new QMUIDialog.EditTextDialogBuilder(c);
    }

//    /**
//     * 这个链接为giteeApi，更换你的gitee地址或其他实现方式，目的是为了更新版本
//     */
//    public static void showUpdateDialog(AppCompatActivity activity, String url, double version, View v) {
//        EasyHttp.get(activity).api(new GiteeApi(url))
//                .request(new SimpleCallBack<GiteeApk>(activity) {
//                    @Override
//                    public void succeed(GiteeApk result) {
//                        try {
//                            if (version < Float.parseFloat(result.getTagName().substring(1))) {//如果版本小于就通知更新
//                                new QMUIDialog.MessageDialogBuilder(activity)
//                                        .setTitle("版本更新")
//                                        .setMessage("当前有新版本，请问是否更新")
//                                        .addAction("取消", (dialog, index) -> dialog.dismiss())
//                                        .addAction("确定", (dialog, index) -> {
//                                            easyDownloadingPopups(activity, result.getTagName(), result.getAssets().get(0).getBrowserDownloadUrl(), v);
//                                            dialog.dismiss();
//                                        })
//                                        .show();
//                            }
//                        } catch (Exception e) {
//                            TipUtil.toast("更新失败");
//                        }
//                    }
//                });
//    }
//
//    /**
//     * 简易的下载弹窗
//     */
//    public static void easyDownloadingPopups(AppCompatActivity activity, String fileName, String url, View v) {
//        final View inflate = LayoutInflater.from(activity).inflate(R.layout.dialog_downloading, null, true);
//        TextView tv = inflate.findViewById(R.id.tv_popup_download_num);
//        ProgressBar pg = inflate.findViewById(R.id.pg_popup_download);
//        final QMUIFullScreenPopup qmuiFullScreenPopup = QMUIPopups.fullScreenPopup(activity)
//                .addView(inflate)
//                .closeBtn(false)
//                .skinManager(QMUISkinManager.defaultInstance(activity));
////                .onBlankClick(popup -> Toast.makeText(activity, "点击到空白区域", Toast.LENGTH_SHORT).show())
////                .onDismiss(() -> Toast.makeText(activity, "onDismiss", Toast.LENGTH_SHORT).show());
//        qmuiFullScreenPopup.show(v);
//        EasyHttp.download(activity)
//                .method(HttpMethod.GET)
//                .file(new File(Environment.getExternalStorageDirectory(), "c_" + fileName + ".apk"))
//                .url(url)
////                .md5("2E8BDD7686474A7BC4A51ADC3667CABF")//用来判断是否重复下载
//                .listener(new OnDownloadListener() {
//
//                    @Override
//                    public void onStart(File file) {
//                    }
//
//                    @Override
//                    public void onProgress(File file, int progress) {
//                        pg.setProgress(progress);
//                        tv.setText(progress + "%");
//                    }
//
//                    @Override
//                    public void onComplete(File file) {
//                        qmuiFullScreenPopup.dismiss();
//                        TipUtil.toast("下载完成：" + file.getPath());
//                        AppUtils.installApp(file);
//                    }
//
//                    @Override
//                    public void onError(File file, Exception e) {
//                        qmuiFullScreenPopup.dismiss();
//                        TipUtil.toast("下载出错：" + e.getMessage());
//                    }
//
//                    @Override
//                    public void onEnd(File file) {
//                        TipUtil.dismiss();
//                    }
//
//                }).start();
//    }


}
